package com.ubxtech.gateway.properties;

import com.ubxtech.core.dto.LoginAppSecretConfig;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;

import java.util.*;

/**
 * @author Victor.Xiao
 * @since 2023-08-22 14:41
 **/

@Data
@ConfigurationProperties(prefix = CustomGatewayProperties.PREFIX)
@RefreshScope
public class CustomGatewayProperties {

    public static final String PREFIX = "ubxtech.gateway";
    /**
     * 是否要接口鉴权,需要微服务配合,微服务启动时把需要鉴权的接口存储到redis
     */
    private Integer permissionFlag=0;

    /**
     * 是否启用灰度,1:启用,0:不起用,默认1
     */
    private String grayFlag="1";

    /** 但是灰度时,是轮训还是随机,1:轮询,2:随机,默认轮询 */
    private String balanceType="1";

    /**
     * 是否启用gateway鉴权,1:启用,0:不起用,默认1
     */
    private Integer authFlag = 1;

    /**
     * 是否打印日志,1:启用,0:不起用,默认1
     */
    private Integer logFlag = 1;
    /**
     * 忽略打印日志的pattern
     */
    private List<String> logExcludePath = new ArrayList<>();

    /**
     * 排除掉url校验鉴权
     */
    private List<String> excludePath = new ArrayList<>();

    /**
     * 排除掉鉴权的服务
     */
    private List<String> excludeServiceId = new ArrayList<>();

    /**
     * 待实现,改VersionGrayLoadBalancerRule 和GrayRoundRobinLoadBalancer即可
     * IP灰度,key是ip列表,value是灰度版本规则,例如SZ-NS-VERSION1,BA-VERSION2
     */
    private Map<String, String> grayIpList = new HashMap<>();

    /**
     * 待实现,改VersionGrayLoadBalancerRule 和GrayRoundRobinLoadBalancer即可
     * 城市灰度
     */
    private Map<String, String> grayCityList = new HashMap<>();

    /**
     * 待实现,改VersionGrayLoadBalancerRule 和GrayRoundRobinLoadBalancer即可
     * 用户灰度
     */
    private Map<String, String> grayUserList = new HashMap<>();
    /**
     * 待实现,改VersionGrayLoadBalancerRule 和GrayRoundRobinLoadBalancer即可
     * 来源灰度
     */
    private Map<String, String> grayOriginList = new HashMap<>();

    /** 静态资源配置，key 表示路径规则，value 表示转发地址 ,示例,默认主页:ubxtech.gateway.static-resources.'[/]'=file:C:/xxx/test.html,或者xxx.'[/test/**]'=file:C:/xxx/  */
    private Map<String, String> staticResources = new LinkedHashMap<>();

    /** appId sign鉴权用 */
    private List<LoginAppSecretConfig> appSecretConfigs = new ArrayList<>();

    /** 监听服务上下线 */
    private String upDownServiceId = "ubt-cml-cloud-msg";

}
